const {origin} = require("../conf/web")
module.exports = async (ctx, next) => {
  //console.log(ctx)
  let ori = ctx.request.header.origin
  ctx.set('Access-Control-Allow-Origin', "*")
  ctx.set('Access-Control-Allow-Headers', 'Content-Type, Content-Length, TOKEN, Authorization, Accept, X-Requested-With')
  ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS')
  ctx.set("Access-Control-Allow-Credentials", true)
  if (ctx.method === "OPTIONS") {
   if (origin.indexOf(ori) > -1) {
      ctx.body = 200
   }
   console.log(1)
  } else {
    await next()
  }
}
